package com.xebia.lightning.converter;

import com.mongodb.BasicDBObject;
import com.mongodb.DBObject;

public class LocationJobCountVOReadConverter implements org.springframework.core.convert.converter.Converter<DBObject, LocationJobCountVO> {

    @Override
    public LocationJobCountVO convert(DBObject source) {
        LocationJobCountVO vo = new LocationJobCountVO();
        vo.setId((String) source.get("_id"));
        Object object = source.get("value");
        if (object instanceof BasicDBObject) {
            BasicDBObject dbObject = (BasicDBObject) object;
            vo.setValue(dbObject.getLong("count"));
        } else if (object instanceof Double) {
            vo.setValue(((Double) object).longValue());
        }
        return vo;
    }

}
